Imports SERPS.ICdataLogic
Imports System.Data
Imports System.Data.SqlClient
Public Class frmProductSearch
    Inherits System.Windows.Forms.Form
    Dim icpAdd As frmProductMasterAdd
    Dim icpEdit As ICproductsEdit
    Friend WithEvents GroupBox1 As System.Windows.Forms.GroupBox
    Friend WithEvents cmdSearch As DevComponents.DotNetBar.ButtonX
    Friend WithEvents cmdExit As DevComponents.DotNetBar.ButtonX
    Friend WithEvents cmbDept As DevComponents.DotNetBar.Controls.ComboBoxEx
    Friend WithEvents GroupPanel1 As DevComponents.DotNetBar.Controls.GroupPanel
    Friend WithEvents cmbSupplier As DevComponents.DotNetBar.Controls.ComboBoxEx


#Region " Windows Form Designer generated code "

    Public Sub New()
        MyBase.New()

        'This call is required by the Windows Form Designer.
        InitializeComponent()

        'Add any initialization after the InitializeComponent() call

    End Sub

    'Form overrides dispose to clean up the component list.
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.
    Friend WithEvents dgProduct As System.Windows.Forms.DataGrid
    Friend WithEvents ttHelp As System.Windows.Forms.ToolTip
    Friend WithEvents Label1 As System.Windows.Forms.Label
    Friend WithEvents tbSearch As System.Windows.Forms.TextBox
    Friend WithEvents rbProdCode As System.Windows.Forms.RadioButton
    Friend WithEvents rbBarCode As System.Windows.Forms.RadioButton
    Friend WithEvents rbManCode As System.Windows.Forms.RadioButton
    Friend WithEvents rbDesc As System.Windows.Forms.RadioButton
    Friend WithEvents Label2 As System.Windows.Forms.Label
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.components = New System.ComponentModel.Container()
        Me.dgProduct = New System.Windows.Forms.DataGrid()
        Me.ttHelp = New System.Windows.Forms.ToolTip(Me.components)
        Me.Label1 = New System.Windows.Forms.Label()
        Me.rbManCode = New System.Windows.Forms.RadioButton()
        Me.rbProdCode = New System.Windows.Forms.RadioButton()
        Me.tbSearch = New System.Windows.Forms.TextBox()
        Me.rbBarCode = New System.Windows.Forms.RadioButton()
        Me.rbDesc = New System.Windows.Forms.RadioButton()
        Me.Label2 = New System.Windows.Forms.Label()
        Me.GroupBox1 = New System.Windows.Forms.GroupBox()
        Me.cmbSupplier = New DevComponents.DotNetBar.Controls.ComboBoxEx()
        Me.cmdSearch = New DevComponents.DotNetBar.ButtonX()
        Me.cmdExit = New DevComponents.DotNetBar.ButtonX()
        Me.cmbDept = New DevComponents.DotNetBar.Controls.ComboBoxEx()
        Me.GroupPanel1 = New DevComponents.DotNetBar.Controls.GroupPanel()
        CType(Me.dgProduct, System.ComponentModel.ISupportInitialize).BeginInit()
        Me.GroupBox1.SuspendLayout()
        Me.GroupPanel1.SuspendLayout()
        Me.SuspendLayout()
        '
        'dgProduct
        '
        Me.dgProduct.BackColor = System.Drawing.Color.AliceBlue
        Me.dgProduct.BackgroundColor = System.Drawing.Color.AliceBlue
        Me.dgProduct.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.dgProduct.CaptionVisible = False
        Me.dgProduct.DataMember = ""
        Me.dgProduct.Font = New System.Drawing.Font("Calibri", 11.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.dgProduct.HeaderBackColor = System.Drawing.Color.FromArgb(CType(CType(255, Byte), Integer), CType(CType(192, Byte), Integer), CType(CType(128, Byte), Integer))
        Me.dgProduct.HeaderForeColor = System.Drawing.SystemColors.ControlText
        Me.dgProduct.Location = New System.Drawing.Point(15, 136)
        Me.dgProduct.Name = "dgProduct"
        Me.dgProduct.ReadOnly = True
        Me.dgProduct.Size = New System.Drawing.Size(923, 318)
        Me.dgProduct.TabIndex = 13
        Me.ttHelp.SetToolTip(Me.dgProduct, "Click on Column Header to Sort.  Click in grid to select product")
        '
        'Label1
        '
        Me.Label1.AutoSize = True
        Me.Label1.Font = New System.Drawing.Font("Calibri", 11.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.Label1.ForeColor = System.Drawing.SystemColors.ActiveCaptionText
        Me.Label1.Location = New System.Drawing.Point(104, 292)
        Me.Label1.Name = "Label1"
        Me.Label1.Size = New System.Drawing.Size(495, 18)
        Me.Label1.TabIndex = 46
        Me.Label1.Text = "Select Product with mouse click, then press Enter to insert into previous screen"
        Me.Label1.Visible = False
        '
        'rbManCode
        '
        Me.rbManCode.AutoSize = True
        Me.rbManCode.Font = New System.Drawing.Font("Calibri", 11.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.rbManCode.ForeColor = System.Drawing.SystemColors.ActiveCaptionText
        Me.rbManCode.Location = New System.Drawing.Point(316, 61)
        Me.rbManCode.Name = "rbManCode"
        Me.rbManCode.Size = New System.Drawing.Size(152, 22)
        Me.rbManCode.TabIndex = 47
        Me.rbManCode.Text = "Manuf.Product Code"
        '
        'rbProdCode
        '
        Me.rbProdCode.AutoSize = True
        Me.rbProdCode.Checked = True
        Me.rbProdCode.Font = New System.Drawing.Font("Calibri", 11.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.rbProdCode.ForeColor = System.Drawing.SystemColors.ActiveCaptionText
        Me.rbProdCode.Location = New System.Drawing.Point(14, 61)
        Me.rbProdCode.Name = "rbProdCode"
        Me.rbProdCode.Size = New System.Drawing.Size(109, 22)
        Me.rbProdCode.TabIndex = 48
        Me.rbProdCode.TabStop = True
        Me.rbProdCode.Text = "Product Code"
        '
        'tbSearch
        '
        Me.tbSearch.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.tbSearch.CharacterCasing = System.Windows.Forms.CharacterCasing.Upper
        Me.tbSearch.Font = New System.Drawing.Font("Calibri", 11.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.tbSearch.Location = New System.Drawing.Point(14, 24)
        Me.tbSearch.MaxLength = 50
        Me.tbSearch.Name = "tbSearch"
        Me.tbSearch.Size = New System.Drawing.Size(239, 26)
        Me.tbSearch.TabIndex = 49
        '
        'rbBarCode
        '
        Me.rbBarCode.AutoSize = True
        Me.rbBarCode.Font = New System.Drawing.Font("Calibri", 11.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.rbBarCode.ForeColor = System.Drawing.SystemColors.ActiveCaptionText
        Me.rbBarCode.Location = New System.Drawing.Point(127, 61)
        Me.rbBarCode.Name = "rbBarCode"
        Me.rbBarCode.Size = New System.Drawing.Size(81, 22)
        Me.rbBarCode.TabIndex = 50
        Me.rbBarCode.Text = "Bar Code"
        '
        'rbDesc
        '
        Me.rbDesc.AutoSize = True
        Me.rbDesc.Font = New System.Drawing.Font("Calibri", 11.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.rbDesc.ForeColor = System.Drawing.SystemColors.ActiveCaptionText
        Me.rbDesc.Location = New System.Drawing.Point(214, 61)
        Me.rbDesc.Name = "rbDesc"
        Me.rbDesc.Size = New System.Drawing.Size(96, 22)
        Me.rbDesc.TabIndex = 51
        Me.rbDesc.Text = "Description"
        '
        'Label2
        '
        Me.Label2.AutoSize = True
        Me.Label2.BackColor = System.Drawing.Color.Transparent
        Me.Label2.Font = New System.Drawing.Font("Calibri", 11.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.Label2.ForeColor = System.Drawing.SystemColors.ActiveCaptionText
        Me.Label2.Location = New System.Drawing.Point(11, 8)
        Me.Label2.Name = "Label2"
        Me.Label2.Size = New System.Drawing.Size(101, 18)
        Me.Label2.TabIndex = 55
        Me.Label2.Text = "Select Supplier"
        '
        'GroupBox1
        '
        Me.GroupBox1.BackColor = System.Drawing.Color.Transparent
        Me.GroupBox1.Controls.Add(Me.rbBarCode)
        Me.GroupBox1.Controls.Add(Me.rbManCode)
        Me.GroupBox1.Controls.Add(Me.rbProdCode)
        Me.GroupBox1.Controls.Add(Me.tbSearch)
        Me.GroupBox1.Controls.Add(Me.rbDesc)
        Me.GroupBox1.Location = New System.Drawing.Point(300, 11)
        Me.GroupBox1.Name = "GroupBox1"
        Me.GroupBox1.Size = New System.Drawing.Size(471, 91)
        Me.GroupBox1.TabIndex = 56
        Me.GroupBox1.TabStop = False
        Me.GroupBox1.Text = "Search"
        '
        'cmbSupplier
        '
        Me.cmbSupplier.DisplayMember = "Text"
        Me.cmbSupplier.DrawMode = System.Windows.Forms.DrawMode.OwnerDrawFixed
        Me.cmbSupplier.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList
        Me.cmbSupplier.ItemHeight = 19
        Me.cmbSupplier.Location = New System.Drawing.Point(12, 55)
        Me.cmbSupplier.Name = "cmbSupplier"
        Me.cmbSupplier.Size = New System.Drawing.Size(275, 25)
        Me.cmbSupplier.TabIndex = 226
        '
        'cmdSearch
        '
        Me.cmdSearch.AccessibleRole = System.Windows.Forms.AccessibleRole.PushButton
        Me.cmdSearch.Font = New System.Drawing.Font("Calibri", 11.25!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.cmdSearch.ForeColor = System.Drawing.Color.FromArgb(CType(CType(0, Byte), Integer), CType(CType(0, Byte), Integer), CType(CType(64, Byte), Integer))
        Me.cmdSearch.Location = New System.Drawing.Point(120, 96)
        Me.cmdSearch.Name = "cmdSearch"
        Me.cmdSearch.Size = New System.Drawing.Size(82, 27)
        Me.cmdSearch.TabIndex = 299
        Me.cmdSearch.Text = "Search"
        '
        'cmdExit
        '
        Me.cmdExit.AccessibleRole = System.Windows.Forms.AccessibleRole.PushButton
        Me.cmdExit.Font = New System.Drawing.Font("Calibri", 11.25!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.cmdExit.ForeColor = System.Drawing.Color.FromArgb(CType(CType(0, Byte), Integer), CType(CType(0, Byte), Integer), CType(CType(64, Byte), Integer))
        Me.cmdExit.Location = New System.Drawing.Point(207, 96)
        Me.cmdExit.Name = "cmdExit"
        Me.cmdExit.Size = New System.Drawing.Size(80, 27)
        Me.cmdExit.TabIndex = 298
        Me.cmdExit.Text = "Exit"
        '
        'cmbDept
        '
        Me.cmbDept.DisplayMember = "Text"
        Me.cmbDept.DrawMode = System.Windows.Forms.DrawMode.OwnerDrawFixed
        Me.cmbDept.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList
        Me.cmbDept.ItemHeight = 19
        Me.cmbDept.Location = New System.Drawing.Point(-53, -509)
        Me.cmbDept.Name = "cmbDept"
        Me.cmbDept.Size = New System.Drawing.Size(206, 25)
        Me.cmbDept.TabIndex = 297
        '
        'GroupPanel1
        '
        Me.GroupPanel1.CanvasColor = System.Drawing.SystemColors.Control
        Me.GroupPanel1.ColorSchemeStyle = DevComponents.DotNetBar.eDotNetBarStyle.Office2007
        Me.GroupPanel1.Controls.Add(Me.GroupBox1)
        Me.GroupPanel1.Controls.Add(Me.Label2)
        Me.GroupPanel1.Dock = System.Windows.Forms.DockStyle.Fill
        Me.GroupPanel1.Location = New System.Drawing.Point(0, 0)
        Me.GroupPanel1.Name = "GroupPanel1"
        Me.GroupPanel1.Size = New System.Drawing.Size(950, 468)
        '
        '
        '
        Me.GroupPanel1.Style.BackColor2SchemePart = DevComponents.DotNetBar.eColorSchemePart.PanelBackground2
        Me.GroupPanel1.Style.BackColorGradientAngle = 90
        Me.GroupPanel1.Style.BackColorSchemePart = DevComponents.DotNetBar.eColorSchemePart.PanelBackground
        Me.GroupPanel1.Style.BorderBottom = DevComponents.DotNetBar.eStyleBorderType.Solid
        Me.GroupPanel1.Style.BorderBottomWidth = 1
        Me.GroupPanel1.Style.BorderColorSchemePart = DevComponents.DotNetBar.eColorSchemePart.PanelBorder
        Me.GroupPanel1.Style.BorderLeft = DevComponents.DotNetBar.eStyleBorderType.Solid
        Me.GroupPanel1.Style.BorderLeftWidth = 1
        Me.GroupPanel1.Style.BorderRight = DevComponents.DotNetBar.eStyleBorderType.Solid
        Me.GroupPanel1.Style.BorderRightWidth = 1
        Me.GroupPanel1.Style.BorderTop = DevComponents.DotNetBar.eStyleBorderType.Solid
        Me.GroupPanel1.Style.BorderTopWidth = 1
        Me.GroupPanel1.Style.CornerDiameter = 4
        Me.GroupPanel1.Style.CornerType = DevComponents.DotNetBar.eCornerType.Rounded
        Me.GroupPanel1.Style.TextAlignment = DevComponents.DotNetBar.eStyleTextAlignment.Center
        Me.GroupPanel1.Style.TextColorSchemePart = DevComponents.DotNetBar.eColorSchemePart.PanelText
        Me.GroupPanel1.Style.TextLineAlignment = DevComponents.DotNetBar.eStyleTextAlignment.Near
        Me.GroupPanel1.TabIndex = 300
        Me.GroupPanel1.Text = "Product Search"
        '
        'frmProductSearch
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(7, 19)
        Me.BackColor = System.Drawing.Color.LightSteelBlue
        Me.ClientSize = New System.Drawing.Size(950, 468)
        Me.ControlBox = False
        Me.Controls.Add(Me.cmdSearch)
        Me.Controls.Add(Me.cmdExit)
        Me.Controls.Add(Me.cmbDept)
        Me.Controls.Add(Me.cmbSupplier)
        Me.Controls.Add(Me.dgProduct)
        Me.Controls.Add(Me.Label1)
        Me.Controls.Add(Me.GroupPanel1)
        Me.Font = New System.Drawing.Font("Calibri", 11.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.ForeColor = System.Drawing.SystemColors.ControlLightLight
        Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle
        Me.Location = New System.Drawing.Point(30, 35)
        Me.MaximizeBox = False
        Me.MinimizeBox = False
        Me.Name = "frmProductSearch"
        Me.ShowInTaskbar = False
        Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
        CType(Me.dgProduct, System.ComponentModel.ISupportInitialize).EndInit()
        Me.GroupBox1.ResumeLayout(False)
        Me.GroupBox1.PerformLayout()
        Me.GroupPanel1.ResumeLayout(False)
        Me.GroupPanel1.PerformLayout()
        Me.ResumeLayout(False)
        Me.PerformLayout()

    End Sub

#End Region

    Private Sub ICproducts_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim ICdata As New ICdataLogic
        Dim ds2 As DataSet
        ds2 = ICdata.GetCompanySuppliers(CompanyID)
        Dim dRow As DataRow
        dRow = ds2.Tables(0).NewRow()
        dRow("SupID") = 0
        dRow("SupName") = "ALL SUPPLIERS"
        ds2.Tables(0).Rows.Add(dRow)
        cmbSupplier.DataSource = ds2.Tables(0)
        cmbSupplier.ValueMember = "SupID"
        cmbSupplier.DisplayMember = "SupName"
        cmbSupplier.SelectedValue = 0
        ICdata = Nothing
        Call LoadData()
    End Sub
    Private Sub LoadData()
        Dim ICdata As New ICdataLogic
        Dim ds As DataSet
        ds = ICdata.GetBarCodes(CompanyID)
        dgProduct.DataSource = ds.Tables(0)
        With dgProduct
            ' .BackgroundColor = GridBackgroundColor
            .TableStyles.Clear()
            .CaptionBackColor = System.Drawing.Color.SlateBlue
            .CaptionForeColor = System.Drawing.Color.LemonChiffon
            .AllowSorting = True
            .AlternatingBackColor = System.Drawing.Color.AliceBlue
            .ParentRowsBackColor = System.Drawing.Color.Lavender
            .ParentRowsForeColor = System.Drawing.Color.SlateBlue
            .HeaderBackColor = System.Drawing.Color.LemonChiffon
            .AllowNavigation = False
            .ParentRowsVisible = False
            .RowHeadersVisible = False
        End With
        Dim cm As CurrencyManager = BindingContext(dgProduct.DataSource, dgProduct.DataMember)
        Dim dv As DataView = cm.List
        dv.AllowNew = False
        dgformat(ds.Tables(0).Rows.Count)
        ICdata = Nothing
    End Sub
    Private Sub dgformat(ByVal RowCount As Integer)
        Dim grdTableStyle As New DataGridTableStyle
        With grdTableStyle
            .AlternatingBackColor = Color.AliceBlue
            .HeaderFont = New Font("calibri", 9.0!, FontStyle.Bold)
            .MappingName = "PRODUCT"
            .PreferredColumnWidth = 160
            .HeaderBackColor = Color.LightSlateGray
            .HeaderForeColor = Color.LightCyan
            .PreferredRowHeight = 15
            .RowHeadersVisible = False
            .RowHeaderWidth = 0
        End With
        Dim cs1 As DataGridColumnStyle
        cs1 = New DataGridTextBoxColumn
        cs1.Width = 0
        cs1.MappingName = "PRODUCTID"
        cs1.HeaderText = "CODE"
        cs1.NullText = ""
        cs1.ReadOnly = True
        grdTableStyle.GridColumnStyles.Add(cs1)
        '
        cs1 = New DataGridTextBoxColumn
        cs1.Width = 150
        cs1.MappingName = "PRODUCTBARCODE"
        cs1.HeaderText = "BAR CODE"
        cs1.NullText = ""
        cs1.ReadOnly = True
        grdTableStyle.GridColumnStyles.Add(cs1)
        '
        cs1 = New DataGridTextBoxColumn
        cs1.Width = 125
        cs1.MappingName = "PRODUCTCODE"
        cs1.HeaderText = "CODE"
        cs1.NullText = ""
        cs1.ReadOnly = True
        grdTableStyle.GridColumnStyles.Add(cs1)
        '
        cs1 = New DataGridTextBoxColumn
        cs1.Width = 125
        cs1.MappingName = "MANUFPRODUCTCODE"
        cs1.HeaderText = "MANUF.CODE"
        cs1.NullText = ""
        cs1.ReadOnly = True
        grdTableStyle.GridColumnStyles.Add(cs1)
        '
        cs1 = New DataGridTextBoxColumn
        cs1.Width = 250
        cs1.MappingName = "SHORTDESCRIPTIONE"
        cs1.HeaderText = "DESCRIPTION"
        cs1.NullText = ""
        cs1.ReadOnly = True
        grdTableStyle.GridColumnStyles.Add(cs1)
        '
        cs1 = New DataGridTextBoxColumn
        cs1.Width = 125
        cs1.MappingName = "FIRSTPRICE"
        cs1.HeaderText = "PRICE -RSP"
        cs1.NullText = ""
        cs1.ReadOnly = True
        cs1.Alignment = HorizontalAlignment.Right
        grdTableStyle.GridColumnStyles.Add(cs1)

        cs1 = New DataGridTextBoxColumn
        cs1.Width = 125
        cs1.MappingName = "AVERAGECOST"
        cs1.HeaderText = "AVG. COST"
        cs1.NullText = ""
        cs1.ReadOnly = True
        cs1.Alignment = HorizontalAlignment.Right
        grdTableStyle.GridColumnStyles.Add(cs1)
        '
        dgProduct.TableStyles.Add(grdTableStyle)
    End Sub
    Private Sub cmdExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdExit.Click
        SearchBarCode = ""
        SearchProductID = 0
        SearchProduct = ""
        Me.Close()
    End Sub

    Private Sub dgProduct_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles dgProduct.MouseUp
        Dim pt As New Point(e.X, e.Y)
        Dim hti As DataGrid.HitTestInfo = dgProduct.HitTest(pt)
        If hti.Type = DataGrid.HitTestType.Cell Then
            dgProduct.CurrentCell = New DataGridCell(hti.Row, hti.Column)
            dgProduct.Select(hti.Row)
        End If
    End Sub

    Private Sub dgProduct_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles dgProduct.KeyUp
        If e.KeyCode = Keys.Enter Then
            Dim CurrentRow As Integer = dgProduct.CurrentCell.RowNumber
            SearchBarCode = dgProduct.Item(CurrentRow, 1)
            SearchProductID = dgProduct.Item(CurrentRow, 0)
            SearchProduct = dgProduct.Item(CurrentRow, 2)

            Me.Close()
        End If
    End Sub

    Private Sub DoSearch()
        Dim mrow As Integer
        Dim cm As CurrencyManager = BindingContext(dgProduct.DataSource, dgProduct.DataMember)
        Dim dv As DataView = cm.List
        mrow = dv.Count
        Dim n As Integer
        Dim strSh As String
        strSh = tbSearch.Text.Trim
        Dim intLen As Integer = strSh.Length

        dgProduct.ResetSelectionBackColor()
        dgProduct.ResetSelectionForeColor()
        dgProduct.ResetForeColor()
        dgProduct.ResetBackColor()
        dgProduct.ResetAlternatingBackColor()
        Dim ICdata As New ICdataLogic
        Dim ds As DataSet
        If intLen > 0 Then
            If rbManCode.Checked = True Then
                ds = ICdata.SearchProduct(CompanyID, "ManufProductCode", strSh, cmbSupplier.SelectedValue)
                dgProduct.DataSource = ds.Tables(0)
            Else
                If rbProdCode.Checked = True Then
                    ds = ICdata.SearchProduct(CompanyID, "ProductCode", strSh, cmbSupplier.SelectedValue)
                    dgProduct.DataSource = ds.Tables(0)
                Else
                    If rbBarCode.Checked = True Then
                        ds = ICdata.SearchProduct(CompanyID, "ProductBarCode", strSh, cmbSupplier.SelectedValue)
                        dgProduct.DataSource = ds.Tables(0)
                    Else
                        ds = ICdata.SearchProduct(CompanyID, "ShortDescriptionE", strSh, cmbSupplier.SelectedValue)
                        dgProduct.DataSource = ds.Tables(0)
                    End If
                End If
            End If
        End If
        If intLen = 0 And cmbSupplier.SelectedValue = 0 Then
            ds = ICdata.GetBarCodes(CompanyID)
            dgProduct.DataSource = ds.Tables(0)
        End If
        If cmbSupplier.SelectedValue > 0 And intLen = 0 Then
            ds = ICdata.GetBarCodesBySupplier(CompanyID, cmbSupplier.SelectedValue)
            dgProduct.DataSource = ds.Tables(0)
        End If
        If dgProduct.VisibleRowCount > 0 Then
            Dim CurrentRow As Integer = dgProduct.CurrentCell.RowNumber
            dgProduct.Select(0)
        End If
        ICdata = Nothing
        tbSearch.Focus()
    End Sub
    Private Sub DoSearch2()
        Dim mrow As Integer
        Dim cm As CurrencyManager = BindingContext(dgProduct.DataSource, dgProduct.DataMember)
        Dim dv As DataView = cm.List
        mrow = dv.Count

        Dim strSh As String
        strSh = tbSearch.Text.Trim
        Dim intLen As Integer = strSh.Length
        Dim pCode As String
        dgProduct.ResetSelectionBackColor()
        dgProduct.ResetSelectionForeColor()
        dgProduct.ResetForeColor()
        dgProduct.ResetBackColor()
        dgProduct.ResetAlternatingBackColor()
        Dim ICdata As New ICdataLogic
        Dim ds As DataSet
        If intLen > 0 Then
            If rbManCode.Checked = True Then
                ds = ICdata.SearchProduct(CompanyID, "ManufProductCode", strSh, cmbSupplier.SelectedValue)
                dgProduct.DataSource = ds.Tables(0)
            Else
                If rbProdCode.Checked = True Then
                    ds = ICdata.SearchProduct(CompanyID, "ProductCode", strSh, cmbSupplier.SelectedValue)
                    dgProduct.DataSource = ds.Tables(0)
                Else
                    If rbBarCode.Checked = True Then
                        ds = ICdata.SearchProduct(CompanyID, "ProductBarCode", strSh, cmbSupplier.SelectedValue)
                        dgProduct.DataSource = ds.Tables(0)
                    Else
                        ds = ICdata.SearchProduct(CompanyID, "ShortDescriptionE", strSh, cmbSupplier.SelectedValue)
                        dgProduct.DataSource = ds.Tables(0)
                    End If
                End If
            End If
        End If
        If intLen = 0 And cmbSupplier.SelectedValue = 0 Then
            ds = ICdata.GetBarCodes(CompanyID)
            dgProduct.DataSource = ds.Tables(0)
        End If
        If cmbSupplier.SelectedValue > 0 And intLen = 0 Then
            ds = ICdata.GetBarCodesBySupplier(CompanyID, cmbSupplier.SelectedValue)
            dgProduct.DataSource = ds.Tables(0)
        End If
        If dgProduct.VisibleRowCount > 0 Then
            Dim CurrentRow As Integer = dgProduct.CurrentCell.RowNumber
            dgProduct.Select(0)
        End If
        ICdata = Nothing
    End Sub
    'Private Sub rbBarCode_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles rbBarCode.Click
    '    DoSearch()
    'End Sub

    'Private Sub rbManCode_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles rbManCode.Click
    '    DoSearch()
    'End Sub

    'Private Sub rbProdCode_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles rbProdCode.Click
    '    DoSearch()
    'End Sub

    Private Sub cmbSupplier_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmbSupplier.SelectedIndexChanged
        If IsNumeric(cmbSupplier.SelectedValue) Then
            LoadData()
            DoSearch()
        End If
    End Sub

    Private Sub cmdSearch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdSearch.Click
        Call DoSearch()
    End Sub

End Class
